package collection;

/**
 * 使用TreeMap时map中的key要实现Comparable接口,重写public int compareTo(Object o)方法
 * 直接用sout(object)打印对象时，如果object里没有toString方法，会输出对象的信息，有的话就会默认
 * 调用toString方法
 */
public class Person implements Comparable<Person> {
    private String name;
    private Integer age;

    public Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public int compareTo(Person person) {
        return age.intValue() - person.getAge().intValue();
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
